import smtplib
import time
from email.mime.text import MIMEText
from email.header import Header
smil_host = "smtp.qq.com" # qq邮箱服务器
smil_pass = '****'  # 填入发送方邮箱的授权码,登录qq邮箱获取
sender = '2430684870@qq.com'  # 发送方邮箱
receivers = ['2430684870@qq.com','3321884853@qq.com']  # 收件人邮箱

subject = "通知"  # 主题
content = f"<p>通知：<p>" \
          f"<p style='text-indent:2em;'>所有老师于今天下午第三节课下课三楼西头大办公室开会<p>" \
          f"<p align='right'>王凤龙<p>" \
          f"<p align='right'>{time.strftime('%Y-%m-%d', time.localtime())}<p>"# 正文
msg = MIMEText(content,'html',"utf-8")
msg['Subject'] = subject
msg['From'] = Header("王凤龙", 'utf-8') # 发件人
msg['To'] =  Header("通知", 'utf-8') # 收件人
try:
    s = smtplib.SMTP_SSL(smil_host, 465) # 邮件服务器及端口号
    s.login(sender, smil_pass)
    s.sendmail(sender,receivers, msg.as_string())
    print("发送成功")
except s.SMTPException:
    print("发送失败")
finally:
    s.quit()
